//
//  ByBallApi.m
//  caipiao_ios
//
//  Created by mc on 2018/7/25.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBallApi.h"

@implementation ByBallApi


//足球近期赛事获取
+ (void)getFootBallMatch:(ByNetModel *)model
                 success:(void(^)(ByNetBaseResult *result))success
                 failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self post:@"/football/match" params:params success:^(id result) {
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}



+ (NSString *)toJSONData:(id)theData{
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        return [[NSString alloc] initWithData:jsonData
                                     encoding:NSUTF8StringEncoding];;
    }else{
        return @"";
    }
}


//足球投注校验
+ (void)footballVerify:(ByNetModel *)model
               success:(void(^)(ByNetBaseResult *result))success
               failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.numDic) {
        [params setObject:[self toJSONData:model.numDic] forKey:@"num"];
    }
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }
    
    
    if (model.free_pass) {
        [params setObject:model.free_pass forKey:@"free_pass"];
    }
    SLog(@"校验参数 = %@", params);
    [self post:@"/football/verify" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}


//足球近期赛事获取
+ (void)getBasketBallMatch:(ByNetModel *)model
                   success:(void(^)(ByNetBaseResult *result))success
                   failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self post:@"/basketball/match" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
}


//足球投注
+ (void)BasketBallCreateOrder:(ByNetModel *)model
                      success:(void(^)(ByNetBaseResult *result))success
                      failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.numDic) {
        [params setObject:[self toJSONData:model.numDic] forKey:@"num"];
    }
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }
    
    
    if (model.free_pass) {
        [params setObject:model.free_pass forKey:@"free_pass"];
    }
    [self post:@"/basketball/create_order" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


//足球投注校验
+ (void)BasketBallVerify:(ByNetModel *)model
                 success:(void(^)(ByNetBaseResult *result))success
                 failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.numDic) {
        [params setObject:[self toJSONData:model.numDic] forKey:@"num"];
    }
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }
    
    
    if (model.free_pass) {
        [params setObject:model.free_pass forKey:@"free_pass"];
    }
    
    NSLog(@"numDic = %@,multiple = %@,free_pass = %@", model.numDic, model.multiple,model.free_pass);
    [self post:@"/basketball/verify" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
}


//足球奖金优化
+ (void)BasketBallComputingSchemeData:(NSDictionary *)params
                              success:(void(^)(ByNetBaseResult *result))success
                              failure:(void(^)(ByNetBaseResult *result))failure {
    
    [self post:@"/bonus/optimize" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


//奖金优化足球投注
+ (void)footballOptimizationCreateOrder:(ByNetModel *)model
                                success:(void(^)(ByNetBaseResult *result))success
                                failure:(void(^)(ByNetBaseResult *result))failure {
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.numArray) {
        [params setObject:[self toJSONData:model.numArray] forKey:@"num"];
    }
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }
    
    
    if (model.free_pass) {
        [params setObject:model.free_pass forKey:@"free_pass"];
    }
    
    if (model.order_type) {
        
        [params setObject:model.order_type forKey:@"order_type"];
       
        
    }
    
    if (model.origin_numDic) {
        [params setObject:[self toJSONData:model.origin_numDic] forKey:@"origin_num"];
    }
    
    
    SLog(@"优化足球投注参数 = %@", params);
    [self post:@"/football/create_order" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}


//奖金优化篮球投注
+ (void)basketBallOptimizationCreateOrder:(ByNetModel *)model
                                  success:(void(^)(ByNetBaseResult *result))success
                                  failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.numArray) {
        [params setObject:[self toJSONData:model.numArray] forKey:@"num"];
    }
    
    if (model.multiple) {
        [params setObject:model.multiple forKey:@"multiple"];
    }
    
    
    if (model.free_pass) {
        [params setObject:model.free_pass forKey:@"free_pass"];
    }
    
    if (model.order_type) {
        
        [params setObject:model.order_type forKey:@"order_type"];
        
        
    }
    
    if (model.origin_numDic) {
        [params setObject:[self toJSONData:model.origin_numDic] forKey:@"origin_num"];
    }
    
    
    SLog(@"优化足球投注参数 = %@", params);
    [self post:@"/basketball/create_order" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
    
}


@end
